#!/usr/bin/env python
# -*- coding: utf-8 -*-

from selenium.webdriver.common.by import By
from po import Page


class oaindex(Page):
    # 定位器
    logout_loc = (By.LINK_TEXT, u"退出")
    help_loc = (By.LINK_TEXT, u"帮助")
    refresh_loc = (By.LINK_TEXT, u"刷新")
    style_loc = (By.LINK_TEXT, u"样式v")
    remind_loc = (By.PARTIAL_LINK_TEXT, u"提醒")

    style_jingdian_loc = (By.ID, 'menuitem-1129-itemEl')
    style_lanse_loc = (By.ID, 'menuitem-1130-itemEl')
    style_heian_loc = (By.ID, 'menuitem-1131-itemEl')
    style_huise_loc = (By.ID, 'menuitem-1132-itemEl')

    search_img_loc = (By.CLASS_NAME, "x-tool-img x-tool-search")
    collapse_img_loc = (By.CLASS_NAME, "x-tool-img x-tool-collapse")
    expand_img_loc = (By.ID, "tool-1057-toolEl")
    refresh_img_loc = (By.CLASS_NAME, "x-tool-img x-tool-refresh")
    collapse_left_img_loc = (By.CLASS_NAME, "x-tool-img x-tool-collapse-left")

    login_mobile_loc = (By.ID, 'loginmobile_title')
    login_mobile_cancel = (By.ID, 'loginmobile_cancel')
    login_mobile_btn_loc = (By.ID, 'button-1048')
    chat_loc = (By.ID, 'button-1050')
    reload_loc = (By.ID, 'button-1052')
    max_loc = (By.ID, 'button-1054')

    center_2_loc = (By.XPATH, '/html/body/div[4]/div/div/div[2]/div/a[2]/span/span/span')

    def get_2_center(self):
        return self.find_element(*self.center_2_loc)

    def login_mobile_click(self):
        self.find_element(*self.login_mobile_btn_loc).click()

    def login_mobile_cancel_click(self):
        self.find_element(*self.login_mobile_cancel).click()

    def reload_click(self):
        self.find_element(*self.reload_loc).click()

    def max_click(self):
        self.find_element(*self.max_loc).click()

    def get_login_mobile_wind_title(self):
        return self.find_element(*self.login_mobile_loc).text

    def chat_click(self):
        self.find_element(*self.chat_loc).click()

    def logout_link_click(self):
        self.find_element(*self.logout_loc).click()

    def get_logou_link(self):
        return self.is_element_present(By.LINK_TEXT, u"退出")

    def help_link_click(self):
        self.find_element(*self.help_loc).click()

    def refresh_link_click(self):
        self.find_element(*self.refresh_loc).click()

    def style_link_click(self):
        self.find_element(*self.style_loc).click()

    def remind_link_click(self):
        self.find_element(*self.remind_loc).click()

    def get_remind_wind(self):
        return self.find_element(*self.center_2_loc)

    def get_jingdian_style(self):
        return self.find_element(*self.style_jingdian_loc)

    def get_lanse_style(self):
        return self.find_element(*self.style_lanse_loc)

    def get_heian_style(self):
        return self.find_element(*self.style_heian_loc)

    def get_huise_style(self):
        return self.find_element(*self.style_huise_loc)

    def get_expand(self):
        return self.find_element(*self.expand_img_loc)

    def isselected_style(self, *loc):
        text = self.find_element(*loc).get_attribute("innerHTML")
        instr = 'style="background-image:url(mode/icons/ok.png);"'
        return text.find(instr) > -1

    def isselected_jingdian_style(self):
        text = self.find_element(*self.style_jingdian_loc).get_attribute("innerHTML")
        instr = 'style="background-image:url(mode/icons/ok.png);"'
        return text.find(instr) > -1

    def isselected_heian_style(self):
        text = self.find_element(*self.style_heian_loc).get_attribute("innerHTML")
        instr = 'style="background-image:url(mode/icons/ok.png);"'
        return text.find(instr) > -1

